package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;

import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingLevelController
 * @Author jack
 * @Date 2024-08-27
 */
@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级相关接口")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;


    /**
     * 查询所有
     *
     * @return
     */
    @ApiOperation("查询所有等级")
    @GetMapping("/listAll")
    public ResponseResult install() {
        List<NursingLevelVo> list = nursingLevelService.install();
        return ResponseResult.success(list);
    }

    @ApiOperation("新增")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody NursingLevelVo nursingLevelVo) {
        nursingLevelService.insert(nursingLevelVo);
        return ResponseResult.success();
    }

    @ApiOperation("条件分页查询")
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<NursingLevelVo>> listByPage(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize,
            @RequestParam(value = "name") String name,
            @RequestParam(value = "status") Integer status) {
        PageResponse<NursingLevelVo> nursingLevelVoPageResponse = nursingLevelService.listByPage(pageNum, pageSize, name, status);
        return ResponseResult.success(nursingLevelVoPageResponse);
    }

    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public ResponseResult serch(@PathVariable Integer id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.serch(id);
        return ResponseResult.success(nursingLevelVo);
    }

    @ApiOperation("修改")
    @PutMapping("/update")
    public ResponseResult update(@RequestBody NursingLevelVo nursingLevelVo) {
        nursingLevelService.update(nursingLevelVo);
        return ResponseResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable(value = "id") Long id) {
        nursingLevelService.delete(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult changeStatus(
            @PathVariable(value = "id") Integer id,
            @PathVariable(value = "status") Integer status) {
        nursingLevelService.changeStatus(id,status);
        return ResponseResult.success();
    }
}
